<?php
/**
 * Created by PhpStorm.
 * User: 程阳
 * Date: 2017/2/27
 * Time: 21:20
 */

namespace Common\Controller;


class HomeController extends BaseController
{
    public function __construct()
    {
        parent::__construct();
        if(isset($_SESSION['home']['user'])){
            $this->assign("user",$_SESSION['home']['user']);
        }
        $this->getCagte();
    }

    //生成验证码
    public function verify(){
        $config =    array(
            'fontSize'    =>    30,    // 验证码字体大小
            'length'      =>    3,     // 验证码位数
            'useNoise'    =>    false, // 关闭验证码杂点
        );
        $verify = new \Think\Verify($config);
        $verify->entry();
    }


// 验证码验证
    // 检测输入的验证码是否正确，$code为用户输入的验证码字符串
    function check_verify($code, $id = ''){
        $verify = new \Think\Verify();
        return $verify->check($code, $id);
    }

    public function getCagte(){
        $cate = M('Class')->where("pid=0")->select();
        $cates = M('Class')->select();
        foreach($cate as $k => $v){
            foreach($cates as $kk => $vv){
                if($vv['pid'] == $v['cid']){
                    $cate[$k]['sonid'][] = $vv['cid'];
                }
            }
//            dd($cate[$k]['sonid']);
            $map['cid'] = ['in',$cate[$k]['sonid']];
            if($cate[$k]['sonid']){
                $cate[$k]['sons'] = M('Goods')->where($map)->select();
            }
        }
        $this->assign('cate',$cate);

    }
}